package personnel.department.pages.addpage;

import java.util.List;
import java.util.Set;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;

import personnel.department.pages.PDTable;
import personnel.department.dao.entity.Translation;

public class TranslationEditor extends AbstractTableEditor<Translation> {

	public TranslationEditor(CTabFolder tabFolder) {
		super(tabFolder, "Переведен в подразделение");
	}
	
	public TranslationEditor(CTabFolder tabFolder, Set<Translation> translations) {
		super(tabFolder, "Переведен в подразделение", translations);
	}

	@Override
	public PDTable<Translation> createTable(Composite parent) {
		return new PDTable<Translation>(parent) {

			@Override
			public List<Translation> setModelProvider() {
				return getModel();
			}

			@Override
			protected void createColumns(Composite parent, TableViewer viewer) {
				String[] titles = { "Основная работа", "Внешнее совместительство", "Внутреннее совместительство",
						"Ставка", "Причина перевода", "Структурное подразделение"};
				int[] bounds = { 150, 170, 180, 100, 150, 170};

				TableViewerColumn col = createTableViewerColumn(getViewer(), titles[0], bounds[0], 0);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return e.getWork().getBaseWork();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[1], bounds[1], 1);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return e.getWork().getExternalWork();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[2], bounds[2], 2);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return e.getWork().getInternalWork();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[3], bounds[3], 3);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return String.valueOf(e.getRate());
					}
				});

				col = createTableViewerColumn(getViewer(), titles[4], bounds[4], 4);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return e.getCauseOfTranslation();
					}
				});

				col = createTableViewerColumn(getViewer(), titles[5], bounds[5], 5);
				col.setLabelProvider(new ColumnLabelProvider() {
					@Override
					public String getText(Object element) {
						Translation e = (Translation) element;
						return e.getSubdivision().getSubdivisionName();
					}
				});

			}
		};
	}

}
